#include "./view.h"

/*********SGUI 文本框模板**********
使用方法：


占用资源：
obj->data[0] 是否按下
obj->data[1] (默认回调)
obj->data[2] 标题
obj->data[3] _FNT指针
obj->data[4] 文本
obj->data[5] 类型
obj->data[6] 最多
obj->data[7] 对话框ID
obj->data[8] 对话框回调
*********************************/

//创建输入框
sObj* sGuiNewEdit(sSpr*spr,char*title,char*text,_FNT*fnt,int type,int max,sEditClick click)
{
 sObj *obj = sNewObj(0,0,spr);
 obj->eve = sGuiEditEve;
 obj->data[0] = FALSE;
 obj->data[1] = (int)sGuiEditClick;
 obj->data[2] = (int)title;
 obj->data[3] = (int)fnt;
 obj->data[4] = (int)text;
 obj->data[5] = type;
 obj->data[6] = max;
 obj->data[7] = -1;
 obj->data[8] = (int)click;
 return obj;
}

//对话框回调
void sGuiEditClick(sObj*obj,int act)
{
 char *title =
 ex_coding((char*)obj->data[2],
 strlen((char*)obj->data[2]),
  "UTF-8","unicode");
 char *text =
 ex_coding((char*)obj->data[4],
 strlen((char*)obj->data[4]),
  "UTF-8","unicode");
 
 if(act==FALSE)
 {
  if(obj->data[7]==-1)
  {
   obj->data[7] = 
   editcreate(title,text,
   obj->data[5],obj->data[6]);
  }
 }
}

//监控对话框
void sGuiEditEve(void*ob,int type,int p1,int p2)
{
 sObj*obj = ob;
 sEditClick click = (sEditClick)
 obj->data[8];
 
 //监控回调
 sGuiBtnEve(ob,type,p1,p2);
 
 //对话框事件
 if(MR_DIALOG==type)
 if(DLG_OK==p1||DLG_CANCEL==p1)
 {   
  if(obj->data[7]!=-1)
  {
   char *un = 
   editget(obj->data[7]);
   obj->data[4] = (int)
   ex_coding(un,wstrlen(un),
   "unicode","UTF-8");
   editdel(obj->data[7]);
   obj->data[7] = -1;
  }
  
  if(obj->data[8]!=-1)
   (*click)(obj,type);
 }
}







